﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Expression;
using Castle.ActiveRecord;
using System.ComponentModel;
using Castle.ActiveRecord.Queries;
using Common;
namespace Mang24k99.Model.CLMN
{
    public partial class MKtClmnItems : ActiveRecordValidationBase
    {
        int? _LastNum1;

        int? _LastNum2;

        int? _LastNum3;

        /// <summary>
        /// Selects the scalar query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <returns></returns>
        public static object SelectScalarQuery(ScalarQuery query)
        {
            return ExecuteQuery(query);
        }

        public int? LastNum1
        {
            get
            {
                return _LastNum1;
            }
            set
            {
                _LastNum1 = value;
            }
        }
        public int? LastNum2
        {
            get
            {
                return _LastNum2;
            }
            set
            {
                _LastNum2 = value;
            }
        }
        public int? LastNum3
        {
            get
            {
                return _LastNum3;
            }
            set
            {
                _LastNum3 = value;
            }
        }

       
        

        public string IsHaveChild
        {
            get
            {
                if (ChildNum == 0)
                {
                    return "无";
                }
                else
                {
                    return "有";
                }

            }

        }
        public string TrastarColumns
        {
            get
            {
                return Common.StringHelper.GetMinString(TrastarCompos, 30);
            }
        }
        /// <summary>
        /// Gets a value indicating whether this instance is hide bool.(隐藏复选框选中)
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is hide bool; otherwise, <c>false</c>.
        /// </value>
        public bool IsHideBool
        {
            get
            {
                if (!IsShow.HasValue || IsShow == 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }


        /// <summary>
        /// Gets a value indicating whether this instance is enable hide.(隐藏复选框是否可用)
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is enable hide; otherwise, <c>false</c>.
        /// </value>
        public bool IsEnableHide
        {
            get
            {
                if (ColumnAttrib==99)
                {
                    return false;
                }
                else
                {
                    return true;
                }
                
            }
           
        }
        /// <summary>
        /// Gets a value indicating whether this instance is delete enable.(是否允许删除)
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is delete enable; otherwise, <c>false</c>.
        /// </value>
        public bool IsDeleteEnable
        {
            get
            {
                if (ChildNum == 0&&(ColumnAttrib!=99))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
        public bool IsEnableEdit
        {
            get
            {
                if (IsReltrastar==0)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
        }
        /// <summary>
        /// Gets the column name first.
        /// </summary>
        /// <value>The column name first.</value>
        public string ColumnNameFirst
        {
            get
            {
                switch (ColumnLayer)
                {
                    case 1:
                        return ColumnName;
                        break;
                    case 2:
                    case 3:
                    case 4:
                        return GetColumnName(1);
                        break;
                    default:
                        return "";
                        break;
                }

            }
        }
        /// <summary>
        /// Gets the column name second.
        /// </summary>
        /// <value>The column name second.</value>
        public string ColumnNameSecond
        {
            get
            {
                switch (ColumnLayer)
                {
                    
                    case 2:
                        return ColumnName;
                        break;
                    case 3:
                    case 4:
                        return GetColumnName(2);
                        break;
                    default:
                        return "";
                        break;
                }

            }
        }

        /// <summary>
        /// Gets the column name third.
        /// </summary>
        /// <value>The column name third.</value>
        public string ColumnNameThird
        {
            get
            {
                switch (ColumnLayer)
                {
                    
                    case 3:
                        return ColumnName;
                        break;
                    case 4:
                        return GetColumnName(3);
                        break;
                    default:
                        return "";
                        break;
                }

            }
        }
        /// <summary>
        /// Gets the column name four.
        /// </summary>
        /// <value>The column name four.</value>
        public string ColumnNameFourth
        {
            get
            {
                switch (ColumnLayer)
                {
                    
                    case 4:
                        return ColumnName;
                        break;
                    default:
                        return "";
                        break;
                }

            }
        }

        private string GetColumnName(int layer)
        {
            int? parentNo;
            switch (layer)
            {
                case 1:
                    parentNo = ColumnNofirst;
                    break;
                case 2:
                    parentNo = ColmunNosecond;
                    break;
                case 3:
                    parentNo = ColumnNothird;
                    break;
                default:
                    return "";
            }

            MKtClmnItems model = SelectByPrimaryKey(parentNo);
            if (model != null)
            {
                return model.ColumnName;
            }
            else
            {
                return "";
            }
        }
    }
}
